<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">

            <a-dropdown v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
              <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}} <a-icon type="down" /> </a-button>
              <a-menu slot="overlay">
                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0" alias="sysJobEdit" :butn-icon="'edit'"
                             :butn-type="'primary'" :show-no-right="false" @click="editOne"><a-icon type="edit"  />{{$ti18('rxList.editBtn','编辑')}}</a-menu-item>
                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0" alias="sysJobDelete" :butn-icon="'delete'" :butn-type="'danger'"
                             :show-no-right="false" @click="delByIds(selectedRowKeys)"><a-icon type="delete" />{{$ti18('rxList.delBtn','删除')}}</a-menu-item>
              </a-menu>
            </a-dropdown>
          </div>
          <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
        </div>
        <div slot="searchbar" btnalign="right"  v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
          <a-form layout="vertical">
                <a-form-item :label="i18n('form.name','名称')">
                    <a-input :placeholder="i18n('form.name','名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                </a-form-item>
                <a-form-item :label="i18n('jobList.remarks','备注')">
                    <a-input :placeholder="i18n('jobList.remarks','备注','input')" v-model="queryParam.Q_REMARK__S_LK"/>
                </a-form-item>
                <a-form-item :label="i18n('form.status','状态')">
                    <a-input-number :min="0" :max="1000000" :placeholder="i18n('jobList.statusDesc','请输入状态(0为禁用,1为启用)')"
                                    v-model="queryParam.Q_STATUS__I_EQ"/>
                </a-form-item>

          </a-form>
        </div>
        <rx-grid
                ref="table"
                :allowRowSelect="true"
                :multiSelect="true"
                :columns="columns"
                :defaultPageSize="10"
                url="/api-system/system/core/sysJob/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="id"
                @selectChange="onSelectChange"
        >
           <span slot="status" slot-scope="{ text, record }">
              <a-tag :color="statusMap[text].color">
              <span>{{statusMap[text].text}}</span>
              </a-tag>
           </span>
           <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                 <span v-if="editEnable && showBtn(false)" @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                 <span v-if="removeEnable && showBtn(false)" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                 <span v-if="showBtn(false)" @click="run(record.id)">{{i18n('jobList.executeBtn','执行')}}</span>
           </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import SysJobApi from '@/api/system/core/sysJob'
  import SysJobEdit from './SysJobEdit'
  import {BaseList,RxFit,RxGrid } from "@lowcode/jpaas-common-lib";
  export default {
    name: 'SysJobList',
    mixins: [BaseList],
    components: {
      RxFit
    },
    data() {
      return {
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 40,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: this.i18n('form.name','名称'), dataIndex: 'name', width: 100},
          {title: this.i18n('jobList.jobTask','JOB任务'), dataIndex: 'jobTask', width: 100},
          {title: this.i18n('form.status','状态'), dataIndex: 'status', width: 100, scopedSlots: {customRender: 'status'}},
          {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],
        component:SysJobEdit,
        comment:this.i18n('jobList.comment','系统定时任务'),
        widthHeight:['800px','600px'],
        fitSearch:false,
        statusMap: {
          "1": {color: 'green', text: this.i18n('form.enable','启用')},
          "0": {color: 'red', text: this.i18n('form.disable','停用')},
        },
      }
    },
    methods:{
      i18n(name,text,key){
          return this.$ti18(name,text,"SysJobTask",key);
      },
      delById(ids){
        return SysJobApi.del({ ids: ids.join(',') });
      },
      getListByParams(parameter){
        return SysJobApi.query(parameter)
      },
      run(id){
          SysJobApi.run(id);
      }

    }
  }
</script>
<style scoped>

</style>

